package com.yike.user.controller;

import com.yike.user.param.*;
import com.yike.user.service.AgentService;
import com.yike.user.vo.*;
import lombok.extern.slf4j.Slf4j;
import com.yike.common.base.BaseController;
import com.yike.common.api.ApiResult;
import com.yike.common.pagination.Paging;
import com.yike.common.log.Module;
import com.yike.common.log.OperationLog;
import com.yike.common.enums.OperationLogType;
import org.springframework.validation.annotation.Validated;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 代理商表 控制器
 *
 * @author Sakura
 * @since 2024-08-26
 */
@Slf4j
@RestController
@RequestMapping("/agent")
@Module("user")
@Api(value = "代理商管理API", tags = {"代理商管理"})
public class AgentController extends BaseController {

    @Autowired
    private AgentService agentService;

    /**
     * 添加代理商表
     */
    @PostMapping("/add")
    @OperationLog(name = "添加代理商", type = OperationLogType.ADD)
    @ApiOperation(value = "添加代理商", response = ApiResult.class)
    public ApiResult<Boolean> addAgent(@Validated @RequestBody AddAgentParam addAgentParam) throws Exception {
        boolean flag = agentService.saveAgent(addAgentParam);
        return ApiResult.result(flag);
    }

    /**
     * 将用户设置为代理商
     */
    @PostMapping("/setAgent")
    @OperationLog(name = "设置代理商", type = OperationLogType.UPDATE)
    @ApiOperation(value = "设置代理商", response = ApiResult.class)
    public ApiResult<Boolean> setAgent(@Validated @RequestBody SetAgentParam setAgentParam) throws Exception {
        boolean flag = agentService.setAgent(setAgentParam);
        return ApiResult.result(flag);
    }

    /**
     * 将用户设置为代理商
     */
    @PostMapping("/update")
    @OperationLog(name = "修改代理商", type = OperationLogType.UPDATE)
    @ApiOperation(value = "修改代理商", response = ApiResult.class)
    public ApiResult<Boolean> updateAgent(@Validated @RequestBody UpdateAgentParam updateAgentParam) throws Exception {
        boolean flag = agentService.updateAgent(updateAgentParam);
        return ApiResult.result(flag);
    }

    /**
     * 删除代理商表
     */
    @PostMapping("/delete/{agentNo}")
    @OperationLog(name = "删除代理商表", type = OperationLogType.DELETE)
    @ApiOperation(value = "删除代理商表", response = ApiResult.class)
    public ApiResult<Boolean> deleteAgent(@PathVariable("agentNo") String agentNo) throws Exception {
        boolean flag = agentService.deleteAgent(agentNo);
        return ApiResult.result(flag);
    }

    /**
     * 获取代理商表详情
     */
    @GetMapping("/info/{agentNo}")
    //@OperationLog(name = "代理商表详情", type = OperationLogType.INFO)
    @ApiOperation(value = "代理商表详情", response = AgentVo.class)
    public ApiResult<AgentVo> getAgent(@PathVariable("agentNo") String agentNo) throws Exception {
        AgentVo agentVo = agentService.getAgent(agentNo);
        return ApiResult.ok(agentVo);
    }

    /**
     * 代理商表分页列表
     */
    @PostMapping("/getPageList")
    //@OperationLog(name = "代理商表分页列表", type = OperationLogType.PAGE)
    @ApiOperation(value = "代理商表分页列表", response = AgentVo.class)
    public ApiResult<Paging<AgentVo>> getAgentPageList(@Validated @RequestBody AgentPageParam agentPageParam) throws Exception {
        Paging<AgentVo> paging = agentService.getAgentPageList(agentPageParam);
        return ApiResult.ok(paging);
    }

    /**
     * 下级代理商表分页列表
     */
    @PostMapping("/getSubAgentList")
    //@OperationLog(name = "下级代理商分页列表", type = OperationLogType.PAGE)
    @ApiOperation(value = "下级代理商分页列表", response = AgentVo.class)
    public ApiResult<Paging<AgentVo>> getSubAgentList(@Validated @RequestBody SubAgentPageParam subAgentPageParam) throws Exception {
        Paging<AgentVo> paging = agentService.getSubAgentList(subAgentPageParam);
        return ApiResult.ok(paging);
    }

    @PostMapping("/getAgentDataStatistics")
    //@OperationLog(name = "获取代理商数据统计", type = OperationLogType.INFO)
    @ApiOperation(value = "获取代理商数据统计", response = AgentDataStatisticsVo.class)
    public ApiResult<AgentDataStatisticsVo> getAgentDataStatistics(@Validated @RequestBody AgentDataStatisticsParam agentDataStatisticsParam) throws Exception {
        AgentDataStatisticsVo agentDataStatisticsVo = agentService.getAgentDataStatistics(agentDataStatisticsParam);
        return ApiResult.ok(agentDataStatisticsVo);
    }

    @PostMapping("/getAgentColumnarDataStatistics")
    //@OperationLog(name = "获取代理商柱状数据统计", type = OperationLogType.INFO)
    @ApiOperation(value = "获取代理商柱状数据统计", response = AgentColumnarDataStatisticsVo.class)
    public ApiResult<List<AgentColumnarDataStatisticsVo>> getAgentColumnarDataStatistics(@Validated @RequestBody AgentColumnarDataStatisticsParam agentColumnarDataStatisticsParam) throws Exception {
        List<AgentColumnarDataStatisticsVo> agentColumnarDataStatistics = agentService.getAgentColumnarDataStatistics(agentColumnarDataStatisticsParam);
        return ApiResult.ok(agentColumnarDataStatistics);
    }

    @PostMapping("/getAgentSearchData")
    //@OperationLog(name = "获取代理商搜索结果", type = OperationLogType.INFO)
    @ApiOperation(value = "获取代理商搜索结果", response = AgentSearchDataVo.class)
    public ApiResult<List<AgentSearchDataVo>> getAgentSearchData(@Validated @RequestBody AgentSearchDataParam agentSearchDataParam) throws Exception {
        List<AgentSearchDataVo> agentSearchDataVos = agentService.getAgentSearchData(agentSearchDataParam);
        return ApiResult.ok(agentSearchDataVos);
    }

    @PostMapping("/getAgentSearchList")
    //@OperationLog(name = "获取代理商搜索列表", type = OperationLogType.INFO)
    @ApiOperation(value = "获取代理商搜索列表", response = AgentSearchListVo.class)
    public ApiResult<List<AgentSearchListVo>> getAgentSearchList(@Validated @RequestBody AgentSearchListParam agentSearchListParam) throws Exception {
        List<AgentSearchListVo> agentSearchListVos = agentService.getAgentSearchList(agentSearchListParam);
        return ApiResult.ok(agentSearchListVos);
    }

    @PostMapping("/getAgentDateStatistics")
    //@OperationLog(name = "获取指定日期数据", type = OperationLogType.INFO)
    @ApiOperation(value = "获取指定日期数据", response = AgentDateStatisticsVo.class)
    public ApiResult<AgentDateStatisticsVo> getAgentDateStatistics(@Validated @RequestBody AgentSearchListParam agentSearchListParam) throws Exception {
        AgentDateStatisticsVo agentDateStatistics = agentService.getAgentDateStatistics(agentSearchListParam);
        return ApiResult.ok(agentDateStatistics);
    }

}

